package com.bdqn.shequ.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.shequ.common.utils.PageUtils;
import com.bdqn.shequ.common.utils.Query;
import com.bdqn.shequ.modules.sys.dao.TcActivityDao;
import com.bdqn.shequ.modules.sys.entity.TcActivityEntity;
import com.bdqn.shequ.modules.sys.service.TcActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("tcActivityService")
public class TcActivityServiceImpl extends ServiceImpl<TcActivityDao, TcActivityEntity> implements TcActivityService {

    @Autowired
    private TcActivityService tcActivityService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TcActivityEntity> page = null;
        if(params.containsKey("status") && !params.get("status").equals(null)){
            if(!params.get("status").equals("0")){
                page = this.page(
                        new Query<TcActivityEntity>().getPage(params),
                        new QueryWrapper<TcActivityEntity>().like("ACTIVITY_STATUS","ACTIVITY").orderByDesc("ID")
                );
            }else if(!params.get("status").equals("1")){
                page = this.page(
                        new Query<TcActivityEntity>().getPage(params),
                        new QueryWrapper<TcActivityEntity>().like("ACTIVITY_STATUS","APPLY").orderByDesc("ID")
                );
            }
        }

        return new PageUtils(page);
    }

    @Override
    public boolean updateStatus(Long activityId, String status) {
        TcActivityEntity ta=new TcActivityEntity();
        ta.setActivityStatus(status);
        return this.update(ta,new QueryWrapper<TcActivityEntity>().eq("ID",activityId));
    }
}
